package org.example.musicserver.controller;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.example.musicserver.common.Result;
import org.example.musicserver.entity.Song;
import org.example.musicserver.service.SongService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/song/")
public class SongController {

    @Resource
    private SongService songService;

    // 返回指定歌曲ID的歌曲
    @GetMapping("detail")
    public Result songOfId(@RequestParam int id) {
        return songService.songOfId(id);
    }

    //返回所有歌曲
    @GetMapping("all")
    public Result songOfId(@RequestParam(required = false) String query) {
        return Result.success("获取所有歌曲信息成功",songService.getAllSong(query));
    }

    //返回某位歌手ID的所有歌曲
    @GetMapping("singerAll")
    public Result songOfSingerId(@RequestParam int id) {
        return songService.songOfSingerId(id);
    }

    @PostMapping("add")
    public Result addSong(@RequestBody Song song){
        return songService.addSong(song);
    }

    @PostMapping("update")
    public Result updateSong(@RequestBody Song song){
        return songService.updateSong(song);
    }

    @GetMapping("delete")
    public Result deleteSong(@RequestParam Integer id){
        return songService.deleteSong(id);
    }

    @Operation(summary = "关键词搜索")
    @GetMapping("selectList")
    public Result selectList(@RequestParam String query){
        return songService.selectList(query);
    }

}

